package cn.tedu.start.controller.petcontroller;

import cn.tedu.commons.response.JsonResult;
import cn.tedu.pojo.pet.dto.PetCategoryDTO;
import cn.tedu.pojo.pet.vo.PetCategoryVO;
import cn.tedu.service.petcommodity.IPetCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@Api(tags = "2，宠物品种模块")
@RestController
@RequestMapping("/category")
public class PetCategoryController {
    @Autowired(required = false)
    private IPetCategoryService petCategoryService;

    @ApiOperation("管理员添加宠物品种")
    @GetMapping("/add")
    public JsonResult addCategory(PetCategoryDTO petCategoryDTO){
        petCategoryService.addCategory(petCategoryDTO);
        return JsonResult.ok("添加类别成功");
    }

    @ApiOperation("管理员修改宠物品种名称")
    @GetMapping("/update/name")
    public JsonResult updateCategory(String oldName,String newName){
        petCategoryService.updatePetCategory(oldName,newName);
        return JsonResult.ok("修改宠物品种成功");
    }

    @ApiOperation("管理员修改宠物是否启用")
    @GetMapping("/update/delete")
    public JsonResult updateIsDelete(String categoryName,Integer isDelete){
        petCategoryService.updateIsDelete(categoryName,isDelete);
        return JsonResult.ok("修改启用状态成功");
    }

    @ApiOperation("获取相应类别名称下的宠物品种列表")
    @GetMapping("/listbytypeid")
    public JsonResult<List<PetCategoryVO>> getListByTypeId(String typeName){
        petCategoryService.getListByType(typeName);
        return JsonResult.ok(petCategoryService.getListByType(typeName));
    }
}
